<?php

declare(strict_types=1);

namespace App\CustHub\Model;

use Mine\MineModel;

/**
 * @property int $id 
 * @property int $uid 
 * @property int $main_uid 
 * @property string $title 标题
 * @property int $corp_id 企业ID
 * @property array $aud_cfg 受众配置
 * @property array $content 推送内容
 * @property int $push_type 计划推送类型：0=定时型-单次 1=定时型-重复 2=触发型-完成条件
 * @property string $begin_time 发送开始时间
 * @property string $end_time 发送结束时间
 * @property array $cycle_cfg 推送周期配置
 * @property int $push_tgt_switch 推送目标开关：0=关 1=开
 * @property array $push_tgt_cfg 推送目标配置
 * @property int $status 状态：0=创建中 1=等待中 2=发送中 3=已完成 4=暂停中 5=已取消
 * @property int $contact_count 客户数量
 * @property int $reach_count 触发数量
 * @property int $completed_count 完成数量
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 更新时间
 * @property int $is_running 任务是否正在执行：0=否 1=是
 * @property-read null|\Hyperf\Database\Model\Collection|ChRobot[] $robots 
 * @property-read null|\Hyperf\Database\Model\Collection|ChSmartPushSchemeSubTask[] $subTask
 */
class ChSmartPushScheme extends MineModel
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'ch_smart_push_scheme';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'uid', 'main_uid', 'title', 'corp_id', 'aud_cfg', 'content', 'push_type', 'begin_time', 'end_time', 'cycle_cfg', 'push_tgt_switch', 'push_tgt_cfg', 'status', 'contact_count', 'reach_count', 'completed_count', 'created_at', 'updated_at', 'is_running'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'uid' => 'integer', 'main_uid' => 'integer', 'corp_id' => 'integer', 'aud_cfg' => 'array', 'content' => 'array', 'push_type' => 'integer', 'cycle_cfg' => 'array', 'push_tgt_switch' => 'integer', 'push_tgt_cfg' => 'array', 'status' => 'integer', 'contact_count' => 'integer', 'reach_count' => 'integer', 'completed_count' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'is_running' => 'integer'];

    /**
     * 子任务
     * @return \Hyperf\Database\Model\Relations\HasMany
     */
    public function subTask(): \Hyperf\Database\Model\Relations\HasMany
    {
        return $this->hasMany(ChSmartPushSchemeSubTask::class, 'scheme_id', 'id');
    }

    public function robots(): \Hyperf\Database\Model\Relations\BelongsToMany
    {
        return $this->belongsToMany(ChRobot::class, 'ch_smart_push_scheme_robot', 'scheme_id', 'robot_id');
    }

    public function corp()
    {
        return $this->hasOne(ChCorp::class,'id','corp_id');
    }
}
